package jtk.project4.fleet.screen.AddTireInventory;

import java.sql.SQLException;

import jtk.project4.fleet.FleetModel;
import jtk.project4.fleet.domain.TireInv;
import jtk.project4.fleet.event.TireInventoryEvent;
import jtk.project4.fleet.screen.AddTireInventory.AddTireInventoryView;
import jtk.project4.fleet.task.LoadTireInvTask;
import nl.coderight.jazz.Controller;

public class AddTireInventoryController extends Controller{
	private AddTireInventoryView addtireinventoryView;
	private FleetModel fleetModel;
	
	public void handleEvent(TireInventoryEvent evt) throws SQLException {
		TireInv tireInv = fleetModel.getTireInv();
		
		switch (evt.getType()) {
			case SUBMIT:
				
					System.out.println("-di submit-");
					System.out.println(tireInv.getSerialNo());
				
				fleetModel.insertOrUpdateTireInv(tireInv);
				executeTask(new LoadTireInvTask());
		
				break;
				
		default:
			// propagate event to controller
			propagateEvent(evt);
			break;
		}
	}
	
	public void execute() {
		fleetModel = (FleetModel) getModel();
		addtireinventoryView = new AddTireInventoryView();
		setView(addtireinventoryView);
		//System.out.println(fleetModel.getTireInvs().size());
		/*for(int i=0;i<fleetModel.getTireInvs().size();i++){
			System.out.println(fleetModel.getTireInvs().get(i).getSerialNo());
		}*/
		showView();
	}

}
